﻿using Comm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace CJGL
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // Application.Run(new Form1());
            Mutex instance = new Mutex(true, "MutexName", out bool createdNew);
            if (createdNew)
            {

                string NTime = XML.read("NTime", "p.xml");
                DateTime xmlTime = Convert.ToDateTime(NTime);
                    if (NTime!=null&&DateTime.Now < xmlTime)
                    {
                        MessageBox.Show("请修改正确电脑的时间！");
                    }
                    else
                    {
                        XML.write("NTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "p.xml");
                        DateTime EndTime = new DateTime(2025, 12, 15);
                        string pass = XML.read("pass", "p.xml");
                        string dsds = ComputerInfo.GetHDDSerial().Trim();
                        dsds = ComputerInfo.GetEncryptPassword(dsds);
                        if (xmlTime < EndTime && (pass != dsds))
                        {
                            MessageBox.Show("当前软件试用期，到期时间"+ EndTime.ToShortDateString());
                            Application.Run(new Form1());
                        }
                        else
                        {
                            if (pass != dsds)
                            {
                                PassWord passfrom = new PassWord();
                                if (passfrom.ShowDialog() == DialogResult.OK)
                                {
                                    Application.Run(new Form1());
                                }
                            }
                            else
                            {
                                Application.Run(new Form1());
                            }
                            instance.ReleaseMutex();
                        }
                    }


            }
            else
            {
                MessageBox.Show("程序已经在启动中");
                Application.Exit();

            }

        }
    }
}
